package com.taiyo.modules.api.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.taiyo.modules.api.entity.TIdentityEntity;
import com.taiyo.modules.api.service.TIdentityService;
import com.taiyo.common.utils.PageUtils;
import com.taiyo.common.utils.Query;
import com.taiyo.common.utils.R;




/**
 * 身份-一个身份对应多个商品。身份里面的类型一个对应一个商品
 * 
 * @author zkcn
 * @email youeremail@163.com
 * @date 2018-01-16 11:18:30
 */
@RestController
@RequestMapping("/api/tidentity")
public class TIdentityController {
	@Autowired
	private TIdentityService tIdentityService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("api:tidentity:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<TIdentityEntity> tIdentityList = tIdentityService.queryList(query);
		int total = tIdentityService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(tIdentityList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("api:tidentity:info")
	public R info(@PathVariable("id") Long id){
		TIdentityEntity tIdentity = tIdentityService.queryObject(id);
		
		return R.ok().put("tIdentity", tIdentity);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("api:tidentity:save")
	public R save(@RequestBody TIdentityEntity tIdentity){
		tIdentityService.save(tIdentity);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("api:tidentity:update")
	public R update(@RequestBody TIdentityEntity tIdentity){
		tIdentityService.update(tIdentity);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("api:tidentity:delete")
	public R delete(@RequestBody Long[] ids){
		tIdentityService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
